/*
 * Copyright 2012 Marsrutai.lt
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package lt.marsrutai.mobile.android.model;

import java.util.List;

import lt.marsrutai.mobile.android.dao.Identifier;
import lt.marsrutai.mobile.android.util.ParcelUtil;
import lt.marsrutai.mobile.android.widget.FastestRouteSearchDialogItem;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * Bookmark representing fastest route search settings
 * 
 * @author Justas
 */
public class FastestRouteSearchBookmark extends Bookmark {

    public static final Parcelable.Creator<FastestRouteSearchBookmark> CREATOR = new Parcelable.Creator<FastestRouteSearchBookmark>() {

        @Override
        public FastestRouteSearchBookmark createFromParcel(Parcel source) {
            return new FastestRouteSearchBookmark(source);
        }

        @Override
        public FastestRouteSearchBookmark[] newArray(int size) {
            return new FastestRouteSearchBookmark[size];
        }
    };

    private String name;

    private String start;
    private Double startLat;
    private Double startLng;
    private FastestRouteSearchDialogItem startSelectionType;

    private String end;
    private Double endLat;
    private Double endLng;
    private FastestRouteSearchDialogItem endSelectionType;

    private boolean isArrivalInd;

    private int changeCount;
    private int changeDuration;
    private int walkDistance;
    private int walkSpeed;
    private List<String> transportTypes;

    public FastestRouteSearchBookmark() {
    }

    public FastestRouteSearchBookmark(Parcel in) {
        super(in);
        name = in.readString();
        start = in.readString();
        startLat = ParcelUtil.readDouble(in);
        startLng = ParcelUtil.readDouble(in);
        startSelectionType = ParcelUtil.readEnum(in, FastestRouteSearchDialogItem.class);
        end = in.readString();
        endLat = ParcelUtil.readDouble(in);
        endLng = ParcelUtil.readDouble(in);
        endSelectionType = ParcelUtil.readEnum(in, FastestRouteSearchDialogItem.class);
        isArrivalInd = ParcelUtil.readBoolean(in);
        
        changeCount = in.readInt();
        changeDuration = in.readInt();
        walkDistance = in.readInt();
        walkSpeed = in.readInt();
        transportTypes = in.createStringArrayList();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeString(name);
        dest.writeString(start);
        ParcelUtil.writeDouble(dest, startLat);
        ParcelUtil.writeDouble(dest, startLng);
        ParcelUtil.writeEnum(dest, startSelectionType);
        dest.writeString(end);
        ParcelUtil.writeDouble(dest, endLat);
        ParcelUtil.writeDouble(dest, endLng);
        ParcelUtil.writeEnum(dest, endSelectionType);
        ParcelUtil.writeBoolean(dest, isArrivalInd);

        dest.writeInt(changeCount);
        dest.writeInt(changeDuration);
        dest.writeInt(walkDistance);
        dest.writeInt(walkSpeed);
        dest.writeStringList(transportTypes);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Identifier
    public String getStart() {
        return start;
    }

    public void setStart(String start) {
        this.start = start;
    }

    @Identifier
    public String getEnd() {
        return end;
    }

    public void setEnd(String end) {
        this.end = end;
    }

    @Identifier
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Identifier
    public Double getStartLat() {
        return startLat;
    }

    public void setStartLat(Double startLat) {
        this.startLat = startLat;
    }

    @Identifier
    public Double getStartLng() {
        return startLng;
    }

    public void setStartLng(Double startLng) {
        this.startLng = startLng;
    }

    @Identifier
    public FastestRouteSearchDialogItem getStartSelectionType() {
        return startSelectionType;
    }

    public void setStartSelectionType(FastestRouteSearchDialogItem startSelectionType) {
        this.startSelectionType = startSelectionType;
    }

    @Identifier
    public Double getEndLat() {
        return endLat;
    }

    public void setEndLat(Double endLat) {
        this.endLat = endLat;
    }

    @Identifier
    public Double getEndLng() {
        return endLng;
    }

    public void setEndLng(Double endLng) {
        this.endLng = endLng;
    }

    @Identifier
    public FastestRouteSearchDialogItem getEndSelectionType() {
        return endSelectionType;
    }

    public void setEndSelectionType(FastestRouteSearchDialogItem endSelectionType) {
        this.endSelectionType = endSelectionType;
    }

    @Identifier
    public boolean getIsArrivalInd() {
        return isArrivalInd;
    }

    public void setIsArrivalInd(boolean isArrivalInd) {
        this.isArrivalInd = isArrivalInd;
    }

    public int getChangeCount() {
        return changeCount;
    }

    public void setChangeCount(int changeCount) {
        this.changeCount = changeCount;
    }

    public int getChangeDuration() {
        return changeDuration;
    }

    public void setChangeDuration(int changeDuration) {
        this.changeDuration = changeDuration;
    }

    public int getWalkDistance() {
        return walkDistance;
    }

    public void setWalkDistance(int walkDistance) {
        this.walkDistance = walkDistance;
    }

    public int getWalkSpeed() {
        return walkSpeed;
    }

    public void setWalkSpeed(int walkSpeed) {
        this.walkSpeed = walkSpeed;
    }

    public List<String> getTransportTypes() {
        return transportTypes;
    }

    public void setTransportTypes(List<String> transportTypes) {
        this.transportTypes = transportTypes;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + ((end == null) ? 0 : end.hashCode());
        result = prime * result + ((endLat == null) ? 0 : endLat.hashCode());
        result = prime * result + ((endLng == null) ? 0 : endLng.hashCode());
        result = prime * result + ((endSelectionType == null) ? 0 : endSelectionType.hashCode());
        result = prime * result + (isArrivalInd ? 1231 : 1237);
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + ((start == null) ? 0 : start.hashCode());
        result = prime * result + ((startLat == null) ? 0 : startLat.hashCode());
        result = prime * result + ((startLng == null) ? 0 : startLng.hashCode());
        result = prime * result + ((startSelectionType == null) ? 0 : startSelectionType.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!super.equals(obj)) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        FastestRouteSearchBookmark other = (FastestRouteSearchBookmark) obj;
        if (end == null) {
            if (other.end != null) {
                return false;
            }
        }
        else if (!end.equals(other.end)) {
            return false;
        }
        if (endLat == null) {
            if (other.endLat != null) {
                return false;
            }
        }
        else if (!endLat.equals(other.endLat)) {
            return false;
        }
        if (endLng == null) {
            if (other.endLng != null) {
                return false;
            }
        }
        else if (!endLng.equals(other.endLng)) {
            return false;
        }
        if (endSelectionType != other.endSelectionType) {
            return false;
        }
        if (isArrivalInd != other.isArrivalInd) {
            return false;
        }
        if (name == null) {
            if (other.name != null) {
                return false;
            }
        }
        else if (!name.equals(other.name)) {
            return false;
        }
        if (start == null) {
            if (other.start != null) {
                return false;
            }
        }
        else if (!start.equals(other.start)) {
            return false;
        }
        if (startLat == null) {
            if (other.startLat != null) {
                return false;
            }
        }
        else if (!startLat.equals(other.startLat)) {
            return false;
        }
        if (startLng == null) {
            if (other.startLng != null) {
                return false;
            }
        }
        else if (!startLng.equals(other.startLng)) {
            return false;
        }
        if (startSelectionType != other.startSelectionType) {
            return false;
        }
        return true;
    }

}
